package Control;

import javax.swing.ImageIcon;
import javax.swing.JOptionPane;

import Entity.MsgPackage;
import GUI.NewUserAuthGui;
import Entity.User;
import GUI.ScreenManager;

public class RegisterNewUserControl {
	
	private NewUserAuthGui newUserPanel;
	private MsgPackage NewUserMsg;
	private User user;

	public RegisterNewUserControl(){
		newUserPanel= new NewUserAuthGui();
		NewUserMsg= new MsgPackage();
		user= new User();	
	}
	
	public NewUserAuthGui getnewUserPanel(){
		return newUserPanel;
	}
	
	public boolean registerNewUser_pressed(){
		String x=newUserPanel.getTextArea_userName().getText();
		String y=newUserPanel.getTextArea_authorization().getText();
		if(x==null||y==null){
			JOptionPane.showMessageDialog(null, "Not all the fileds all the fill", "ERROR", JOptionPane.ERROR_MESSAGE);
			return false;
		}
		else{
		user.setUserName(Integer.parseInt(newUserPanel.getTextArea_userName().getText()));
		user.setAuthorization(newUserPanel.getTextArea_authorization().getText());
		NewUserMsg.setObject(user);
		NewUserMsg.setOp_code(OP_CODE.REGISTER_NEW_USER);
		ScreenManager.getClient().accept(NewUserMsg);
		JOptionPane.showMessageDialog(null, "The user was updated successfully", "", JOptionPane.INFORMATION_MESSAGE);

		return true;
		}
	}
}
